package com.company;

import java.io.File;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.JFileChooser;

public class Export {

	// [一键导出]调用的方法
	public void exportToCsv() {
		JFileChooser jf = new JFileChooser();
		jf.setFileSelectionMode(JFileChooser.SAVE_DIALOG
				| JFileChooser.DIRECTORIES_ONLY);
		// 弹出具有自定义的approve按钮的自定义文件选择器对话框
		jf.showDialog(null, null);
		File file = jf.getSelectedFile();
		String path = file.getAbsolutePath();// 取得绝对路径

		// 拼接导出文件的路径
		// ·路径：绝对路径+"采购列表"+"yyyyMMddHHmmss"
		path = path + "\\全部学生信息" + ".csv";
		System.out.println("csv导出路径" + path);

		// 获取数据
		Dao MainDB = new Dao();
		List<Object[]> payMainList = null;
		try {
			payMainList = MainDB.selectAll();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		// 获取csv表头
		Object[] names = { "学号", "姓名", "性别", "系别", "寝室", "班级" ,"年级"};

		File f = CSVUtil.createCSVFile(names, payMainList, path);
		if (f != null) {
			Message.getMsg("恭喜，文件导出完毕", "提示消息");
		}

	}
	
	public static void main(String[] args) {
		Export ex=new Export();
		ex.exportToCsv();
	}

	
}
